package me.ereach.streams;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Main12Collectors {
    public static void main(String[] args) {
        List<Movie> movies = List.of(
                new Movie("a", 10),
                new Movie("b", 15),
                new Movie("c", 20)
        );

        System.out.println("===toList");
        var rst1 = movies.stream()
                .collect(Collectors.toList());

        rst1.forEach(x -> System.out.println("Movie { title: " + x.getTitle() + ", likes: " + x.getLikes() + " }"));

        System.out.println("===toSet");
        var rst2 = movies.stream()
                .collect(Collectors.toSet());

        rst2.forEach(x -> System.out.println("Movie { title: " + x.getTitle() + ", likes: " + x.getLikes() + " }"));

        System.out.println("===toMap");
        var rst3 = movies.stream()
                .collect(Collectors.toMap(Movie::getTitle, Movie::getLikes));

        System.out.println(rst3);

        System.out.println("===toHashMap");
        var rst4 = movies.stream()
                .collect(Collectors.toMap(Movie::getTitle, m -> m));

        System.out.println(rst4);

        System.out.println("===toHashMap another type of m");
        var rst5 = movies.stream()
                .collect(Collectors.toMap(Movie::getTitle, Function.identity()));

        System.out.println(rst5);

        System.out.println("===summingInt");
        var rst6 = movies.stream()
                .collect(Collectors.summingInt(Movie::getLikes));

        System.out.println(rst6);

        System.out.println("===summarizingInt");
        var rst7 = movies.stream()
                .collect(Collectors.summarizingInt(Movie::getLikes));

        System.out.println(rst7);

        System.out.println("===joining");
        var rst8 = movies.stream()
                .filter(m -> m.getLikes() > 10)
                .map(Movie::getTitle)
                .collect(Collectors.joining(", "));

        System.out.println(rst8);

    }
}
